<?php
/**
 * Created by PhpStorm.
 * User: nightelf
 * Date: 2020/1/10
 * Time: 9:30
 */

namespace App\Http\Controllers\Admin;


use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Http\Model\PermissionModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class PermissionController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\Response
     * @throws ApiException
     */
    public function lists(Request $request){
        $rules = [
            'isProject' => 'required|integer',
        ];
        $message = [
            'isProject.required' => '获取角色参数失败',
            'isProject.integer' => '角色参数类型错误',
        ];
        $param = $request->only(['isProject']);
        $validator = Validator::make($param, $rules, $message);
        if ($validator->passes()) {
            $permissionModel = new PermissionModel();
            $lists = $permissionModel->lists($param);
            $this->data = $this->listToTree($lists);
        } else {
            throw new ApiException($validator->errors()->first(), 140101);
        }

        return $this->ajaxResult($this->code, $this->msg, $this->data);
    }
}